package com.lxc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lxc.entity.Works;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WorkMapper extends BaseMapper<Works> {

    //根据id多表查询某个数据
    @Select("select * from works where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "chapters", javaType = List.class,
                    many = @Many(select = "com.lxc.mapper.ChapterMapper.getChapteriesByWorkId")),
            @Result(column = "work_picture",property = "workPicture"),
            @Result(column = "name",property = "name"),
            @Result(column = "author_name",property = "authorName"),
            @Result(column = "synopsis",property = "synopsis")
    })
    public Works getWorkById(Integer id);

    /*拆所有数据*/
    //若name和categoryId传入几个查询几个，没有则分页查询第一页
    public IPage<Works> getWorks(IPage<Works> page, @Param("name") String name, @Param("category") String category,Integer pageNum, Integer pageSize);


    @Update("update works set views=#{views} where id=#{id}")
    public void addViews(@Param("id") int id, @Param("views") int views);

    @Select("select w.work_picture,w.name from works w where author_name=#{authorName}")
    List<Works> getWorkByAuthorName(String authorName);

}